package org.lw.consumer.controller;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
import org.lw.consumer.feign.ProviderClient;
import org.lw.consumer.pojo.Order;
import org.lw.consumer.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/consumer")
public class UserClientController {

    @Autowired
    ProviderClient providerClient;  //
    @Autowired
    private  OrderService orderService;
    @PostMapping ("/{username}")
    public String getInfoByUsername( @PathVariable("username") String username,@RequestHeader("X-Request-Color-1") String color) {
        System.out.println("username:" + username);
        System.out.println("color:" + color);

        return providerClient.findProvider(username);

        /*return  restTemplate.getForObject("http://NacosProvider/provider",String.class);*/
        /* return  nacosServerFeign.getInfoByUsername(username);*/
    }
    @GetMapping("/hello")
    public String hello() {
        return providerClient.hello();
    }
    @PostMapping("/")
    public String test(@RequestBody Order order) throws DegradeException {
        return  orderService.create(order);

    }




}
